<template>
  <div class="home">
    <!-- 1、头部的导肮 -->
    <el-row class="head">
      <!-- 左边的logo -->
      <el-col :span="12" class="head-left">
        <img src="../assets/img/logo1.png" alt="" class="img" />
        <div class="title">霸都装饰后台管理系统</div>
        <div class="time">{{ date | dateFormat }}</div>
      </el-col>
      <!-- 右边的用户名和退出 -->
      <el-col :span="12" class="head-right">
        <div class="name">欢迎您:{{ name }}</div>
        <el-button type="primary" @click="logOut">退出</el-button>
      </el-col>
    </el-row>
    <!-- 2、页面的主体 -->
    <div class="main">
      <!-- 左边的导航 -->
      <div :class="['nav', isCollapse ? 'w-64' : 'w-150']">
        <el-tooltip
          class="item"
          effect="light"
          :content="isCollapse ? '点击展开导航' : '点击折叠导航'"
          placement="top-end"
          :enterable="false"
        >
          <div class="collapse-btn fx-center" @click="toggleNav">|||</div>
        </el-tooltip>
        <el-menu
          :default-active="index"
          background-color="#000"
          text-color="#fff"
          active-text-color="#ffd04b"
          :unique-opened="true"
          :collapse="isCollapse"
          :collapse-transition="false"
        >
          <el-submenu
            :class="[isCollapse ? 'w-64' : 'w-150']"
            :index="item.id"
            v-for="(item, index) in arr"
            :key="index"
          >
            <template slot="title">
              <i :class="item.icon"></i>
              <span>{{ item.title }}</span>
            </template>
            <el-menu-item
              :class="[isCollapse ? 'w-64' : 'w-150']"
              v-for="(item1, index1) in item.children"
              :key="index1"
              :index="item1.id"
              @click="goToView(item1.path, item1.id)"
            >
              <template slot="title">
                <i class="el-icon-menu"></i>
                <span>{{ item1.title }}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </div>
      <!-- 右边的主体 -->
      <div class="content">
        <!-- 二级路由 -->
        <router-view></router-view>
      </div>
    </div>
  </div>
</template>
<script>
import arr from '@/assets/js/nav'
import { getToken } from '../utils/token'
export default {
  data() {
    return {
      name: 'admin',
      index: '0',
      arr,
      isCollapse: false,
      date: new Date(),
      id: 0,
    }
  },
  methods: {
    //退出系统
    logOut() {
      sessionStorage.clear()
      this.$router.push('/')
    },
    //caselist
    goToView(path, index) {
      this.index = index
      this.$router.push(path)
    },
    toggleNav() {
      this.isCollapse = !this.isCollapse
    },
    getUserInfo() {
      let { name } = getToken()
      this.name = name
    },
    times() {
      if (this.id) {
        clearInterval(this.id)
      }
      let _this = this
      this.id = setInterval(function () {
        _this.date = new Date()
      }, 1000)
    },
  },
  created() {
    this.times()
  },
  mounted() {
    this.getUserInfo()
  },
}
</script>
<style scoped lang="less">
.flex-ct {
  display: flex;
  align-items: center;
  justify-content: center;
}
.home {
  width: 1366px;
  min-width: 1366px;
  background-color: rgb(255, 255, 255);
  //头部
  .head {
    background-color: #000;
    color: #fff;
    height: 0.6rem;
    .head-left {
      height: 100%;
      .flex-ct;
      justify-content: flex-start;
      padding-left: 0.3rem;
      .img {
        width: 0.3rem;
      }
      .title {
        margin: 0 0.2rem;
        font-size: 0.14rem;
      }
      .time {
        font-size: 0.14rem;
      }
    }
    .head-right {
      font-size: 0.14rem;
      height: 100%;
      .flex-ct;
      padding-right: 0.3rem;
      justify-content: flex-end;
      .name {
        margin-right: 0.2rem;
      }
    }
  }
  //主体
  .main {
    width: 100%;
    display: flex;
    min-height: 6rem;
    .nav-list {
      border: 1px solid blue;
      height: 0.3rem;
    }
    .w-150 {
      width: 150px;
    }
    .w-64 {
      width: 64px;
    }
    .nav {
      background-color: #000;
      .el-menu {
        width: 100%;
        border: none;
        .el-menu-item {
          width: 100%;
          // 默认最小宽度200px
          min-width: 150px;
        }
      }
      .collapse-btn {
        background-color: #31363a;
        color: #fff;
        height: 0.3rem;
      }
    }
    .content {
      flex: 1;
    }
  }
}
</style>
